package com.vhuomai.product.home.mapper;

import com.vhuomai.mybatis.mapper.auto.AutoMapper;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import com.vhuomai.product.entity.BaseProduct;
import com.vhuomai.product.home.dto.HomeProductInfo;
import com.vhuomai.product.home.entity.BaseHomeProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

@Mapper
public interface HomeProductMapper extends AutoMapper<BaseHomeProduct, Integer> {
    BaseHomeProduct findByProduct(@Param("productId") Integer productId);

    @Select("select h.id as home_product_id, p.* from base_home_product h "
        + "left join base_product p on h.product_id = p.id "
        + "where h.category_id = #{categoryId}")
    List<HomeProductInfo> findByCategory(@Param("categoryId") Integer categoryId);

    @Select("<script>select * from base_product p where p.id not in <foreach item=\"item\" index=\"index\" collection=\"list\" open=\"(\" separator=\",\" close=\")\">${item}</foreach></script>")
    Page<BaseProduct> findProductList(@Param("list") Collection<Integer> list, @Param("request") PageRequest request);
}
